package com.efounder.frame.activity;

import android.app.ProgressDialog;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.core.content.res.ResourcesCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.core.xml.StubObject;
import com.efounder.constant.EnvironmentVariable;
import com.efounder.form.application.util.V8Util;
import com.efounder.frame.activity.helper.EFAppAccountMainActivityHelper;
import com.efounder.frame.activity.manager.EFAppAccountMainActivityDownloadManager;
import com.efounder.frame.activity.manager.EFAppAccountMainActivityFragmentManager;
import com.efounder.frame.baseui.EFActivity;
import com.efounder.frame.fragment.EFAppAccountPagerSlidingTabFragment;
import com.efounder.frame.fragment.EFAppAccountTabFragmentInterface;
import com.efounder.frame.manager.AppAccountResDownloader;
import com.efounder.frame.tabbar.EFTabBar;
import com.efounder.frame.tabbar.EFTabBarItem;
import com.efounder.frame.title.EFSimpleTitleView;
import com.efounder.frame.utils.EFAppAccountUtils;
import com.efounder.frame.utils.EFFrameUtils;
import com.efounder.frame.xmlparse.EFAppAccountRegistry;
import com.efounder.frame.xmlparse.EFXmlConstants;
import com.efounder.mobilemanager.R;

import java.io.File;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;

import static com.efounder.frame.utils.Constants.KEY_SETTING_APPID;

/**
 * Created by hudq on 2016/8/16. XX
 * 应用号Activity --在用
 * 一级 Activity
 */
public class EFAppAccountMainActivity extends EFActivity implements EFTabBar
        .OnTabBarItemClickListener,
        EFAppAccountPagerSlidingTabFragment.OnViewPagerMeasureCompleteDelegate,
        EFAppAccountMainActivityInterface, EFAppAccountPagerSlidingTabFragment
                .EFAppAccountPagerSlidingTabFragmentListener,
        AppAccountResDownloader.DownloadAppAccountResourceListener
//        , ReactFragmentInterface, DefaultHardwareBackBtnHandler
{
    private long systemCurrentTime;

    public static final String TAG = "EFAppAccountMainActivity";
    /**
     * 底部TabBar
     **/
    private EFTabBar efTabBar;
    /**
     * 是否缓存fragment
     **/
    private boolean isCacheFragment = true;
    /**
     * 是否同时初始化所有tab对应的fragment
     **/
    private boolean isInitAllTabFragment = false;
    /**
     * 是否是全屏
     */
    private boolean isFullScreen = false;
    /**
     * helper只能new一个
     **/
    private EFAppAccountMainActivityHelper mainActivityHelper;
    /**
     * fragmentManager只能new一个
     **/
    private EFAppAccountMainActivityFragmentManager mainActivityFragmentManager;
    /**
     * 下载管理类
     */
    private EFAppAccountMainActivityDownloadManager downloadManager;
    /**
     * 初始化的position，这个值可以是配置的
     **/
    private int initPosition = -1;

    private List<StubObject> dataList;

    private ProgressDialog progressDialog;
    private Bundle savedInstanceState;

    private Handler handler = new MyHandler(this);
    private String intentType = "";

   // private ReactNativeHost host = null;


    private static class MyHandler extends Handler {
        private WeakReference<EFAppAccountMainActivity> activityWeakReference;

        public MyHandler(EFAppAccountMainActivity activity) {
            this.activityWeakReference = new WeakReference<EFAppAccountMainActivity>(activity);
        }

        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            EFAppAccountMainActivity activity = activityWeakReference.get();
            if (activity != null) {
                switch (msg.what) {
                    case 0:
                        break;
                    case 1:
                        break;
                    case 2:
                        break;
                    case 3://主数据下载完成
                        //进行第三步
                        activity.beginCreateViewInThread();
                        break;
                    case 4:
                        activity.progressDialog.dismiss();
                        //download-5 生成界面
                        activity.beginCreateView(activity.savedInstanceState);
                        break;
                }
            }

        }


    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.w("--", TAG + "-----onCreate--savedInstanceState：" + savedInstanceState);
        this.savedInstanceState = savedInstanceState;

        Boolean isFriend = getIntent().getBooleanExtra("isFriend", true);

        if (!isFriend) {
            this.finish();
            gotoChat();
            return;
        }

        String type = getIntent().getStringExtra("type");//用type判断跳转应用号还是聊天界面
        if ("chat".equals(type) && !new File(EFAppAccountUtils.getAppAccountRootPath()).exists()) {
            this.finish();
            gotoChat();
            return;
        }

        if (EnvironmentVariable.getProperty(KEY_SETTING_APPID, "").equals("OSPOpenPlanet")) {
            //星际通讯
            this.finish();
            gotoChat();
            return;
        }

        init();

        //一、下载应用号资源文件
        downLoadAppResource();

    }

    private void init() {
        //设置不可滑动返回
        getSwipeBackLayout().setEnableGesture(false);
        //XXX-存储全局使用的应用号id
        int appAccountID = getIntent().getIntExtra("id", 0);


        String appAccountName = getIntent().getStringExtra("nickName");
        EFAppAccountUtils.saveAppAccountID(appAccountID);
        EFAppAccountUtils.saveAppAccountName(appAccountName);

        //初始化属性（helper，manager）
        mainActivityHelper = new EFAppAccountMainActivityHelper();
        mainActivityFragmentManager = new EFAppAccountMainActivityFragmentManager(getSupportFragmentManager());
        //实例化下载管理类
        downloadManager = new EFAppAccountMainActivityDownloadManager(this);
    }

    /**
     * 一、下载应用号资源文件
     */
    private void downLoadAppResource() {
//        if (!new File(EFAppAccountUtils.getAppAccountRootPath()).exists()) {//如果本地资源文件不存在
        if (!new File(EFAppAccountUtils.getAppAccountAppFramePath()).exists()) {//如果本地资源文件appframe.xml
            //download-2 检测服务器应用号资源文件是否存在
            downloadManager.checkUrl(new EFAppAccountMainActivityDownloadManager.CheckUrlListener() {
                @Override
                public void onStart() {
                    progressDialog = new ProgressDialog(EFAppAccountMainActivity.this);
                    progressDialog.setMessage("正在初始化界面...");
                    progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                    progressDialog.setCancelable(true);
                    progressDialog.show();
                    progressDialog.setCancelable(true);
                }

                @Override
                public void onSuccess() {
                    //应用号资源文件存在
                    progressDialog.dismiss();
                    //download-3 下载资源文件
                    downloadManager.downloadResource(EFAppAccountMainActivity.this);
                }

                @Override
                public void onFail() {
                    progressDialog.dismiss();
                    EFAppAccountMainActivity.this.finish();
                    gotoChat();
                }
            });

        } else {
            //进行第二步
            downloadMainData();
        }
    }

    /**
     * 一、下载应用号资源文件成功的回调方法
     */
    @Override
    public void onResourceDownloadSuccess() {
        //应用号资源文件下载完成
        //进行第二步
        downloadMainData();
    }


    /**
     * 二、下载主数据
     */
    private void downloadMainData() {
        File fileMDM = new File(EFAppAccountUtils.getAppAccountMDMPath());
        if (!fileMDM.exists() || fileMDM.list().length == 0) {//如果主数据不存在
            if (!fileMDM.exists()) fileMDM.mkdirs();
            //download-2 下载主数据
            downloadManager.downloadMainDataAsync(handler);
        } else {
            //进行第三步
            beginCreateViewInThread();
        }
    }

    /**
     * 三、开始异步创建view
     */
    private void beginCreateViewInThread() {
        progressDialog = new ProgressDialog(this);
        progressDialog.setMessage("正在初始化数据...");
        progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        progressDialog.setCancelable(true);
        progressDialog.show();
        new Thread() {
            @Override
            public void run() {
                super.run();
                //XXX 获取权限,给注册表权限赋值，以便过滤权限
                String gnqxString = EnvironmentVariable.getProperty("gnqx", "");
                List<String> gnqxList = new ArrayList<>();
                if (gnqxString == null || gnqxString.equals("")) {//没有开启权限
                    EFAppAccountRegistry.setPermissionList(null);
                } else if ("无".equals(gnqxString)) {//没有任何权限
                    EFAppAccountRegistry.setPermissionList(gnqxList);
                } else {
                    String[] gnqxStrings = gnqxString.split(";");
                    for (String gnqx : gnqxStrings) {
                        gnqxList.add(gnqx);
                    }
                    EFAppAccountRegistry.setPermissionList(gnqxList);
                }
                try {
                    //1.初始化注册表
                    mainActivityHelper.initRegistry();
                    //创建V8
                    EFAppAccountUtils.V8 = V8Util.createV8();

                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    handler.sendEmptyMessage(4);
                }

            }
        }.start();
    }

    private void beginCreateView(@Nullable Bundle savedInstanceState) {
        setContentView(R.layout.ef_activity_main);
        //1.初始化数据
        initData();

        //2 TODO 如果一级菜单 size==0 有权限管理，并且用户没有任何权限，直接显示聊天fragment\
        //用户自定义了intent
        if (intentType.equals("")) {
            if (EFAppAccountRegistry.getStubListByElementName("menuRoot").size() == 0) {
                initChatTitleView(savedInstanceState);
                try {
                    FragmentManager fragmentManager = getSupportFragmentManager();
                    Fragment fragment = (Fragment) Class.forName(getResources()
                            .getString(R.string.PUBLIC_CHAT_FRAGMENT_PACKAGE_NAME)).newInstance();
                    fragmentManager.beginTransaction().replace(R.id.fragment_container, fragment).commit();
                } catch (Exception e) {
                    e.printStackTrace();
                }
                //!!注意return
                return;
            } else {
                String type = getIntent().getStringExtra("type");//用type判断跳转应用号还是聊天界面
                //XXX 判断如果有消息就跳转聊天界面
                if ("chat".equals(type)) {
//                handler.sendEmptyMessage(1);//跳转聊天界面
                    gotoChat();
                }
            }
        } else {
//            Class weChatDBManager = null;
//            Class chatListManager = null;
//            try {
//                ClassLoader loader = Thread.currentThread().getContextClassLoader();
//                Class<?> clazz = loader.loadClass("com.efounder.chat.db.WeChatDBManager");
//                //获取无参构造器
//                //Constructor<?> cons = clazz.getDeclaredConstructor();
//                //获取有参构造器，根据参数类型。
//                Constructor<?> cons1 = clazz.getDeclaredConstructor(Activity.class);
//                //实例化
//                weChatDBManager = (Class) cons1.newInstance(this);
//            } catch (ClassNotFoundException e) {
//                e.printStackTrace();
//            } catch (NoSuchMethodException e) {
//                e.printStackTrace();
//            } catch (InstantiationException e) {
//                e.printStackTrace();
//            } catch (IllegalAccessException e) {
//                e.printStackTrace();
//            } catch (InvocationTargetException e) {
//                e.printStackTrace();
//            }
//
//            try {
//                ClassLoader loader = Thread.currentThread().getContextClassLoader();
//                Class<?> clazz = loader.loadClass("com.efounder.chat.manager.ChatListManager");
//                //获取无参构造器
//                Constructor<?> cons = clazz.getDeclaredConstructor();
//                //获取有参构造器，根据参数类型。
//                //Constructor<?> cons1 = clazz.getDeclaredConstructor(Context.class);
//                //实例化
//                chatListManager = (Class) cons.newInstance();
//            } catch (ClassNotFoundException e) {
//                e.printStackTrace();
//            } catch (NoSuchMethodException e) {
//                e.printStackTrace();
//            } catch (InstantiationException e) {
//                e.printStackTrace();
//            } catch (IllegalAccessException e) {
//                e.printStackTrace();
//            } catch (InvocationTargetException e) {
//                e.printStackTrace();
//            }
//
//            //WeChatDBManager weChatDBManager = WeChatDBManager.getInstance();
//            int appAccountID = getIntent().getIntExtra("id", 0);
//            // ChatListManager chatListManager = new ChatListManager();
//
//            try {
//                Method m1 = chatListManager.getDeclaredMethod("clearunReadCount",weChatDBManager,int,byte);
//                m1.invoke(c)
//            } catch (NoSuchMethodException e) {
//                e.printStackTrace();
//            }
//
//            chatListManager.clearunReadCount(weChatDBManager, appAccountID, (byte) 0);
//            EventBus.getDefault().post(new UpdateBadgeViewEvent(appAccountID + "", (byte) 2));
        }

        //如果被回收后，重新创建
        if (savedInstanceState != null) {
            int currentPosition = savedInstanceState.getInt("currentPosition");
            //给fragmentManager恢复数据
            mainActivityFragmentManager.setCurrentPosition(currentPosition);
        }
//===========================================================================================================

        //3.初始化底部TabBar
        initTabBar(mainActivityHelper, dataList);
        //在efTabBar实例化之后，将efTabBar与mainActivityFragmentManager绑定
        mainActivityFragmentManager.setEfTabBar(efTabBar);
        //4.处理tltleView
        initTitleView(savedInstanceState);
        //如果第一次onCreate，初始化Fragment，fragment与activity绑定之后，fragment会跟随activity生命周期，自动创建
        if (savedInstanceState == null) {
            if (isCacheFragment && isInitAllTabFragment) {//同时初始化所有tab对应的fragment
                mainActivityFragmentManager.initAllTabFragment(dataList, initPosition);
            } else {
                EFAppAccountPagerSlidingTabFragment efAppAccountPagerSlidingTabFragment = mainActivityFragmentManager.showFragment(initPosition, dataList.get(initPosition)
                        , isCacheFragment);
            }
        }


        //检测是否需要资源更新
        if (AppAccountResDownloader.isNeedUpdate(EFAppAccountUtils.getAppAccountID())) {
            int appAccountID = getIntent().getIntExtra("id", 0);
            new AppAccountResDownloader(this, appAccountID).updateResource();
        }

    }

    private void gotoChat() {
        Bundle bundle = EFFrameUtils.getCurrentActivity().getIntent().getExtras();
        bundle.putInt(EFTransformFragmentActivity.EXTRA_TITLE_LEFT_VISIBILITY,
                View.VISIBLE);
        //fixme 注意跳转聊天之前的 titilebar 是使用的 EFTransformFragmentActivity的 现在通过配置使用fragment自己的
        if (EnvironmentVariable.getProperty("useFragmentTitlrbar", "false").equals("true")) {
            bundle.putBoolean(EFTransformFragmentActivity.EXTRA_HIDE_TITLE_BAR, true);
        } else {
            bundle.putInt(EFTransformFragmentActivity.EXTRA_TITLE_RIGHT_VISIBILITY,
                    View.INVISIBLE);
        }
        bundle.putString(EFTransformFragmentActivity.EXTRA_TITLE_NAME, bundle
                .getString("nickName"));

        try {
            EFFrameUtils.pushFragment((Class<? extends Fragment>) Class.forName
                    (getResources().getString(R.string.PUBLIC_CHAT_FRAGMENT_PACKAGE_NAME)), bundle);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    private void initData() {
        //从注册表中获取数据
        dataList = EFAppAccountRegistry.getStubListByElementName(EFXmlConstants.ELE_MENU_ROOT);
        StubObject mainFrameStub = EFAppAccountRegistry.getStubByID(EFXmlConstants.ID_MAIN_FRAME);
        if (mainFrameStub != null) {
            //isCacheFragment 默认为true
            isCacheFragment = mainFrameStub.getString(EFXmlConstants.ATTR_IS_CACHE_FRAGMENT, "1")
                    .equals("1") ? true : false;
            //isInitAllTabFragment 默认为false
            isInitAllTabFragment = mainFrameStub.getString(EFXmlConstants
                    .ATTR_IS_INIT_ALL_TAB_FRAGMENT, "0").equals("1") ? true : false;
            //isFullScreen 默认是false
            isFullScreen = mainFrameStub.getString(EFXmlConstants
                    .ATTR_IS_FULL_SCREEN, "0").equals("1") ? true : false;
            intentType = mainFrameStub.getString("intentType", "");
            String initPositionStr = mainFrameStub.getString(EFXmlConstants.ATTR_INIT_POSITION,
                    "0");
            try {
                initPosition = Integer.parseInt(initPositionStr);
            } catch (NumberFormatException e) {
                initPosition = 0;
                e.printStackTrace();
            }
        }
    }

    private void initTabBar(EFAppAccountMainActivityHelper mainActivityHelper, List<StubObject>
            dataList) {
        efTabBar = mainActivityHelper.createTabBar(this, dataList);
        // 2.TabBar添加OnTabClickListener
        efTabBar.setOnTabBarItemClickListener(this);
//        efTabBar.setIndicatorNumber(2,2);
        efTabBar.setIndicatorTextColor(ResourcesCompat.getColor(getResources(), R.color.ef_white,
                null));
        //旋转屏幕，savedInstanceState != null,showFragment不会调用,需要自己初始化一下位置
        efTabBar.setSelectedTab(mainActivityFragmentManager.getCurrentPosition());
        if (isFullScreen)
            efTabBar.setVisibility(View.GONE);
    }

    private void initTitleView(Bundle savedInstanceState) {
        hideEFTitleView();
        //设置允许打开左边抽屉
        initDrawerLayout(savedInstanceState);
    }

    private void initChatTitleView(Bundle savedInstanceState) {
        EFSimpleTitleView titleView = getEFTitleView();
        //标题
        String nickName = getIntent().getStringExtra("nickName");
        TextView centerView = (TextView) titleView.getCenterView();
        centerView.setText(nickName);
        //隐藏右侧图标
        titleView.getRightImageView().setVisibility(View.INVISIBLE);
        //配置左侧图标
        ImageView leftImageView = titleView.getLeftImageView();
        StubObject stubObject = EFAppAccountRegistry.getStubByID("main_frame");
        String iconName = stubObject.getString("icon", "");
        leftImageView.setImageDrawable(Drawable.createFromPath(EFAppAccountUtils
                .getAppAccountImagePath() + "/" + iconName));
        leftImageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getDrawerLayout().openDrawer(Gravity.LEFT);
            }
        });

        //设置允许打开左边抽屉
        initDrawerLayout(savedInstanceState);
    }

    /**
     * 初始化DrawerLayout
     */
    private void initDrawerLayout(Bundle savedInstanceState) {
        //设置允许打开左边抽屉
        getDrawerLayout().setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, Gravity.LEFT);
        if (savedInstanceState == null) {
            //TODO 设置左边抽屉Fragment
            try {
                FragmentManager fragmentManager = getSupportFragmentManager();
                Fragment leftFragment = (Fragment) Class.forName("com.efounder.fragment" +
                        ".AppAccountLeftDrawerFragment").newInstance();
                fragmentManager.beginTransaction().replace(getDrawerLayoutLeftLayoutResId(),
                        leftFragment).commit();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    @Override
    protected void onStart() {
        super.onStart();
        Log.w("--", TAG + "-----onStart--");
    }

    @Override
    protected void onResume() {
        super.onResume();
        Log.w("--", TAG + "-----onResume--");
    }

    @Override
    protected void onPause() {
        super.onPause();
        Log.w("--", TAG + "-----onPause--");
    }

    @Override
    protected void onStop() {
        super.onStop();
        Log.w("--", TAG + "-----onStop--");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (progressDialog != null)
            progressDialog.dismiss();
//        clearData();
        Log.w("--", TAG + "-----onDestroy--");
        //FIXME 临时处理arcMenu
//        ArcMenuList.arcMenuList.clear();
    }

    public static void clearData() {
        EFAppAccountRegistry.clearRegister();
        EFAppAccountUtils.applicationContainerMap.clear();
//        //销毁v8
        if (EFAppAccountUtils.V8 != null) {
            V8Util.releaseV8(EFAppAccountUtils.V8);
            EFAppAccountUtils.V8 = null;
        }
    }


    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        //被回收时,保存当前位置
        if (mainActivityFragmentManager != null) {
            outState.putInt("currentPosition", mainActivityFragmentManager.getCurrentPosition());
        } else {
            outState.putInt("currentPosition", 0);
        }

    }

    @Override
    public void onTabBarItemClick(EFTabBarItem EFTabBarItem, int position) {
        if (position == mainActivityFragmentManager.getCurrentPosition()) {
            return;
        }
        efTabBar.clearIndicator(position);
        // TODO tabBar点击事件
        mainActivityFragmentManager.showFragment(position, dataList.get(position), isCacheFragment);
    }

    @Override
    public void onViewPagerMeasureComplete(int position) {
        if (isCacheFragment && isInitAllTabFragment) {//同时初始化所有tab对应的fragment
            if (position != mainActivityFragmentManager.getCurrentPosition())
                mainActivityFragmentManager.hideFragment(position);
        }
    }


    @Override
    public void gotoFragment(int tabFragmentPosition, int viewPagerFragmentPosition) {
        EFAppAccountPagerSlidingTabFragment tabFragment = mainActivityFragmentManager
                .showFragment(tabFragmentPosition, dataList.get(tabFragmentPosition),
                        isCacheFragment);
        if (tabFragment instanceof EFAppAccountTabFragmentInterface) {
            EFAppAccountTabFragmentInterface gotoViewPagerFragmentInterface = tabFragment;
            gotoViewPagerFragmentInterface.gotoViewPagerFragment(viewPagerFragmentPosition);
        }
    }

    @Override
    public void onClickLeftViewListener(View view) {
        getDrawerLayout().openDrawer(Gravity.LEFT);
    }

    @Override
    public void onBackPressed() {

//
//        if (host != null) {
//
//            host.getReactInstanceManager().onBackPressed();
//        } else {
            exitApp();


        //}

    }

    private void exitApp() {
        //拦截返回事件
        if (System.currentTimeMillis() - systemCurrentTime > 3000) {
            Toast.makeText(this, "再按一次退出应用号", Toast.LENGTH_SHORT).show();
            systemCurrentTime = System.currentTimeMillis();
        } else {
            super.onBackPressed();
            //退出应用时，清空缓存数据
            clearData();
        }
    }


    private Fragment reactFragment = null;

    /**
     * 监听按钮点击事件
     *
     * @param keyCode
     * @param event
     * @return
     */
//    @Override
//    public boolean onKeyUp(int keyCode, KeyEvent event) {
//
//        if (host == null) {
//            //没有使用rn模块
//            return super.onKeyUp(keyCode, event);
//        } else {
//            //使用了rn模块判断是否需要拦截点击时间;
//            boolean handled = false;
//
//            if (reactFragment == null) {
//                List<Fragment> fragments = getSupportFragmentManager().getFragments();
//                for (Fragment f : fragments) {
//                    if (f instanceof EFAppAccountPagerSlidingTabFragment) {
//                        List<Fragment> tabFragment = f.getChildFragmentManager().getFragments();
//                        for (Fragment fg : tabFragment) {
//                            if (fg instanceof ReactFragment) {
//                                reactFragment = fg;
//                            }
//                        }
//
//                    }
//                }
//            }
//            if (reactFragment != null) {
//
//                handled = ((ReactFragment) reactFragment).onKeyUp(keyCode, event);
//
//            }
//            return handled || super.onKeyUp(keyCode, event);
//        }
//
//
//    }
//
//
//    /**
//     * @return 给应用号传递ReactNativeHost
//     */
//    public ReactNativeHost getReactNativeHost() {
//
//        Hashtable stubTable = dataList.get(0).getStubTable();
//        String enterFile = (String) stubTable.get("resource");
//        if (TextUtils.isEmpty(enterFile)) {
//            throw new IllegalStateException("必须制定入口文件名字");
//        }
//        if (host == null) {
//            host = new LXReactNativeHost(getApplication(), this, enterFile);
//        }
//        return host;
//
//
//    }
//
//    /**
//     * 当js不消耗返回事件后rn将回调此方法
//     */
//    @Override
//    public void invokeDefaultOnBackPressed() {
//        exitApp();
//    }

}
